<div class="row">
    <div class="col-lg-12">
        <h3 class="page-header">Danh Câu Hỏi Câu Trả Lời</h3>
    </div>
    <!-- /.col-lg-12 -->
</div>
<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-heading">
<!--                <a class="" href="<?php //echo $this->url(array("action"=>"index")) ?>">Index Feedback</a>-->
            </div> 
            <div class="panel-body">               
                <div class="table-reponsive">
                    <div id="jqxgrid">
                        
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
        $(document).ready(function () {
            // prepare the data
            var source =
            {
                datatype: "json",
                datafields:
                [
                    { name: 'Id',type:'int'},
                    { name: 'user_id', type: 'int' },
                    { name: 'title', type: 'string' },
                    { name: 'question', type: 'string' },
                    { name: 'admin_id', type: 'int' },                                           
                    { name: 'answer', type: 'string' }
                ],
                url:'<?php echo $this->baseUrl() ?>/admin/feedback/service',
                sortcolumn: 'user_id',
                sortdirection: 'asc'
               
            };
         var dataAdapter = new $.jqx.dataAdapter(source, {
                loadComplete: function () {
                }
            });
            $("#jqxgrid").jqxGrid(
            {
                width: 1010,
                source: dataAdapter,  
                theme: 'bootstrap',
                pageable: true,
                showfilterrow: true,
                filterable: true,
                autoheight: true,
                sortable: true,
                altrows: true,
                enabletooltips: true,
                selectionmode: 'multiplecellsadvanced',
                columnsResize: true,
                rendergridrows: function (params) {
                    return params.data;
                },
                ready: function () {
                    $("#jqxgrid").jqxGrid('hideColumn', 'Id');
                },
                columns: [
                  {text:'Id',dataField:'Id',cellsalgin:'right',width:0},
                  { text: 'Tên Người Dùng',editable: false, dataField: 'user_id', width: '15%' },
                  { text: 'Tiêu Đề',editable: false, dataField: 'title', width: '20%', },
                  { text: 'Câu Hỏi',editable: false, dataField: 'question', width: '20%' },
                  { text: 'Quản Trị',editable: false, dataField: 'admin_id', width: '15%' },
                  { text: 'Câu Trả Lời', editable: false, dataField: 'answer', width: '20%' },
                  {text: 'Xóa',filtertype: 'none', cellsalign: 'right', align: "center", columnType: 'none', editable: false, sortable: false, dataField: null, cellsrenderer: function (row) {
                          // render custom column.
                          editrow = row;
                          var dataRecord = $("#jqxgrid").jqxGrid('getrowdata',editrow);
                          var url= "<div style='overflow: hidden; text-overflow: ellipsis; padding-bottom: 2px; text-align: center; margin-right: 2px; margin-left: 4px; margin-top: 4px;'><a class='fa fa-trash-o fa-lg'";
                          url = url + "href='#' onclick='return jsdelete("+dataRecord.Id+")'></a></div>";
                          return url;
                      }
              },
              {text: 'Sửa',filtertype: 'none', cellsalign: 'right', align: "center", columnType: 'none', editable: false, sortable: false, dataField: null, cellsrenderer: function (row) {
                          // render custom column.
                          editrow = row;
                          var dataRecord = $("#jqxgrid").jqxGrid('getrowdata',editrow);
                          if(dataRecord.answer != ""){
                               url="";                        
                          }else{
                               var url= "<div style='overflow: hidden; text-overflow: ellipsis; padding-bottom: 2px; text-align: center; margin-right: 2px; margin-left: 4px; margin-top: 4px;'><a class='fa fa-edit fa-lg'";
                               url = url + "href='<?php echo $this->baseUrl() ?>/admin/feedback/edit/id/"+dataRecord.Id+"'></a></div>"
                          }
                          return url;
                      }
                          }
                ]
            });           
        });
    </script>
    <script type="text/javascript">
        function jsdelete(id)
        {                  
            bootbox.confirm("Bạn có chắc muốn xoá câu hỏi - trả lời này không?",function(result){
                if(result==true)
                {
                    return window.location = "<?php echo $this->baseUrl() ?>/admin/feedback/delete/id/"+id;
                }
            });
        }
    </script>
    